package calcul;

import java.util.ArrayList;
import java.util.Scanner;

public class Calculator { 
	
	public static ArrayList<String>  print(int n){
		
		ArrayList<String>Answers=new ArrayList<String>();//参考答案存储
		int m = n/3;                                                        //分数题型题量占三分之一
		int qnum=1;
		int count=0;
		for(int i=0;i<(n-m);i++,qnum++){                                           //开始随机出整数题型
			String intQuestion;
			System.out.print("["+qnum+"] ");
			count++;
			if(count==3){
				intQuestion = CreateIntQuestion.CreateQuestion();
				System.out.println();
				count=0;
			} else{
			 intQuestion = CreateIntQuestion.CreateQuestion();
			}
			Answers.add(intQuestion);
		
	}
		 count=0;
		for(int j=0;j<m;j++,qnum++){
			String fracQuestion;
			System.out.print("["+qnum+"] ");
			count++;
			if(count==3) {
				 fracQuestion =CreateFracQuestion.CreateFQuestion();
				System.out.println();
				count=0;
			}else{
			 fracQuestion =CreateFracQuestion.CreateFQuestion();
			}
			Answers.add(fracQuestion);
		}
		return Answers;
	}
	
	public static void cheack(ArrayList<String>Answers){
		
		ArrayList<String>anslist=new ArrayList<>();
		String str="";
		System.out.println();
		System.out.println("请输入答案，除法结果请保留两位小数：");
		int q=1;
		Scanner sc2=new Scanner(System.in);
		while(!str.equals("ok")){
			if(q==Answers.size()+1)  break;
			System.out.print("["+q+"] ");
			str=sc2.nextLine();
			anslist.add(str);
			q++;
		}
		
		int correct=0;

		int t=0;
		System.out.println("[题号] 参考答案 \t 提交结果");
		System.out.println();
		for (int x=0;x<Answers.size();x++) {                    //检验答案并统计
			if(Answers.get(x).equals(anslist.get(x))){
				correct++;
				t=x+1;
				System.out.println("["+t+"] "+" \t "+Answers.get(x)+" \t "+" \t "+anslist.get(x));
			}else
			{

				t=x+1;
				System.err.println("["+t+"]"+" \t "+Answers.get(x)+" \t "+" \t "+anslist.get(x)+"    !!!!");
			}
	}
		System.out.println("本次练习统计：");
		System.out.println("得分："+correct+"    共"+Answers.size()+"分，正确率： "+(float)correct/Answers.size()*100+"%, 带!!!!为答错的题目。");
		sc2.close();
	}
		
	
	public static void main(String[] args){
		ArrayList<String>Answers=new ArrayList<String>();//参考答案存储
		System.out.println("请输入想要的题目数量：");                         //提示需求数量
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Answers=print(n);
		cheack(Answers);
		sc.close();
	}

}
